#include <string>

#include "MyDate.h"
#include <string>

using std::string;

   string MyDate::conInt(int number) {
        if (number == 0)
            return "0";
        string temp = "";
        string returnvalue = "";
        while (number > 0) {
            temp += number % 10 + 48;
            number /= 10;
        }
        for (int i = 0; i < temp.length(); i++)
            returnvalue += temp[temp.length() - i - 1];
        return returnvalue;
    };

    void MyDate::setDate(string& s) {
        string g = "";
        buf = s ;
        hour = atoi((g + s[0] + s[1]).c_str());
        minute = atoi((g + s[3] + s[4]).c_str());
        day = atoi((g + s[6] + s[7]).c_str());
        month = atoi((g + s[9] + s[10]).c_str());
        year = atoi((g + s[12] + s[13] + s[14] + s[15]).c_str());
    };

    string& MyDate::getstring() {

      if ( buf.size() != 0 )
        return buf;

       string s = "";
        if (hour < 10)
            s += "0" + conInt(hour) + ":";
        else
            s += conInt(hour) + ":";

        if (minute < 10)
            s += "0" + conInt(minute) + "_";
        else
            s += conInt(minute) + "_";

        if (day < 10)
            s += "0" + conInt(day) + ".";
        else
            s += conInt(day) + ".";

        if (month < 10)
            s += "0" + conInt(month) + ".";
        else
            s += conInt(month) + ".";

        s += conInt(year);
        buf = s;
        return buf;
    };



    bool MyDate::operator<(const MyDate& obj2) {
        if (year < obj2.year) return true;
        if (year > obj2.year) return false;

        if (month < obj2.month) return true;
        if (month > obj2.month) return false;

        if (day < obj2.day) return true;
        if (day > obj2.day) return false;

        if (hour < obj2.hour) return true;
        if (hour > obj2.hour) return false;

        if (minute < obj2.minute) return true;
        if (minute > obj2.minute) return false;

        return false;

    };

    bool MyDate::operator>(const MyDate& obj2) {
        if (*(this) < obj2)
            return false;
        else
            return true;
    };

